package com.cndw.kungfu.event.once;

import com.cndw.kungfu.comm.tencent.QQDC;
import com.cndw.kungfu.config.ConstantsIntKey;
import com.cndw.kungfu.config.ConstantsRadio;
import com.cndw.kungfu.domain.Player;
import com.cndw.kungfu.model.Context;
import com.cndw.kungfu.vo.PlayerChangeVO;

/**
 * 角色升级的处理事务
 * 
 * @author fantadust [9677889@qq.com]
 * @date 2011-12-5 下午11:38:01
 */
public class PlayerPayTask implements Runnable {


	private Player player;
	
	private int qqPoint;

	public PlayerPayTask(Player player) {
		this.player = player;
	}

	public PlayerPayTask(Player player,int qqPoint) {
		this.player = player;
		this.qqPoint = qqPoint;
	}	
	@Override
	public void run() {
		try {
			//Context.getTaskServer().autoRaidioTask(player.getPlayerId(), 1);

			PlayerChangeVO change = new PlayerChangeVO();
			int sumPay = Context.getBusinessServer().selectPayGoldSum(player.getPlayerId());
			player.getDataInfo().intDataSet(ConstantsIntKey.payCash, sumPay);
			
			/**
			 * 我的当前充值额度
			 */

			player.getDataInfo().commitSync();
			change.put(PlayerChangeVO.payCash, sumPay);
			change.put(PlayerChangeVO.PLAYER_MAIN, player.toPlayerVO());

			Context.getTcpServer().broadcast(change, ConstantsRadio.playerChange, player.getPlayerId());
			
			if (qqPoint >0 ) {
				QQDC.getInstance().pay(player,qqPoint);
			}
			if (player.getDataInfo().intDataGet(ConstantsIntKey.payTrue) == 0 ) {//修正我的充值标识
				if (Context.getBusinessServer().selectPayGoldSumOnlyQQPay(player.getPlayerId())>0) {
					player.getDataInfo().intDataSet(ConstantsIntKey.payTrue, 1);
					player.getDataInfo().commitSync();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		
	}

}
